﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EBAYVN.DAO;
using EBAYVN.DOMAIN;

namespace EBAYVN.Share
{
    public partial class Login : System.Web.UI.UserControl
    {
        private readonly LoginDAO _objlogin = new LoginDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            Session.RemoveAll();
            if (!IsPostBack)
            {
                this.txtTenDangNhap.Focus();
            }

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (CheckLogin())
            {
                Response.Redirect("~/Default.aspx", false);
            }
        }
        private bool CheckLogin()
        {
            try
            {
                if (Page.IsValid)
                {
                    var Objuser = new USERLOGIN
                    {
                        USERNAME = this.txtTenDangNhap.Text.Trim()
                    };
                    var password=this.txtMatKhau.Text.Trim();
                    Objuser.PASSWORD = password;
                    var Objlogin = _objlogin.CheckLogin(Objuser);
                    if (Objlogin!=null)
                    {
                        Session["user_login"] = Objlogin.USERNAME;
                        return true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                return false;
            }
            return false;
        }
        
    }
}